﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_10
{
    public partial class Form1 : Form
    {
        int[] num;
        string statisticsStr;
        public Form1()
        {
            InitializeComponent();
        }
       

        private void Form1_Load(object sender, EventArgs e)
        {
            button2.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int n = int.Parse(textBox1.Text);
                int min = int.Parse(textBox2.Text);
                int max = int.Parse(textBox3.Text);
                num = new int[n];
                int positive = 0, negative = 0, even = 0, odd = 0;
                Random rnd = new Random();

                // 生成随机数并统计（源码分析核心）
                for (int i = 0; i < n; i++)
                {
                    num[i] = rnd.Next(min, max + 1); // 含max的随机数
                    if (num[i] > 0) positive++;
                    if (num[i] < 0) negative++;
                    if (num[i] % 2 == 0) even++;
                    else odd++;
                }

                // 拼接结果和统计信息
                statisticsStr = $"\r\n正数{positive}个 负数{negative}个 奇数{odd}个 偶数{even}个";
                textBox4.Text = string.Join(" ", num) + statisticsStr;
                button2.Enabled = true; // 启用排序按钮
                button2.Text = "排序"; // 重置排序按钮文本
            }
            catch (FormatException)
            {
                MessageBox.Show("请输入有效整数！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "排序")
            {
                Array.Sort(num); // 正向排序
                button2.Text = "逆序";
            }
            else
            {
                Array.Reverse(num); // 逆向排序
                button2.Text = "排序";
            }
            textBox4.Text = string.Join(" ", num) + statisticsStr;
        }
    }
}
